﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringesindus_iseendakohta_ettevote", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ParingesindusIseendakohtaEttevote))]
    public class ParingesindusIseendakohtaEttevoteSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParingesindusIseendakohtaEttevote clazz;
        
        public ParingesindusIseendakohtaEttevoteSerializer(IParingesindusIseendakohtaEttevote clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            if (clazz.AriregistriKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("arinimi");
            if (clazz.Arinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Arinimi");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_iseendakohta_ettevote>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_iseendakohta_ettevote>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_iseendakohta_ettevote>arinimi", Reader.LocalName);
            }
        }
    }
}
